//
//  MTRFillString.m
//  MTRiPad
//
//  Created by lachesis-zhu on 03/05/2017.
//  Copyright © 2017 lachesis. All rights reserved.
//

#import "MTRFillString.h"

@implementation MTRFillString

+ (NSString *)fillString:(NSString *)string
{
    NSString *returnString;
    //判断是否是纯数字
    if ([MTRFillString isPureInt:string] || [MTRFillString isPureFloat:string]) {
        returnString = string;
    } else {
        if (string.length != 0 && string != nil && string != NULL && ![string isEqual:[NSNull null]]) {
            returnString = string;
        } else {
            returnString = @"--";
        }
    }
    
    return returnString;
}

//判断是否为整形：
+ (BOOL)isPureInt:(NSString *)string{
    NSScanner *scan = [NSScanner scannerWithString:string];
    int val;
    return [scan scanInt:&val] && [scan isAtEnd];
}

//判断是否为浮点形：
+ (BOOL)isPureFloat:(NSString *)string{
    NSScanner *scan = [NSScanner scannerWithString:string];
    float val;
    return[scan scanFloat:&val] && [scan isAtEnd];
}
@end
